package com.example.yqand4v1_1.controller;

import com.example.yqand4v1_1.beans.Result;
import com.example.yqand4v1_1.dto.NewsSearchDTO;
import com.example.yqand4v1_1.dao.entity.News;
import com.example.yqand4v1_1.service.NewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;

    // 新闻查找筛选排序（一个按钮实现）
    @PostMapping(value = "/search")
    public Result<List<News>> search(@RequestBody NewsSearchDTO newsSearchDTO) {
        return Result.success(newsService.search(newsSearchDTO));
    }

    // 新闻详情查看
    @GetMapping(value = "/detail/{id}/{userId}")
    public Result<News> detail(@PathVariable("id") int id, @PathVariable("userId") int userId) {
        return Result.success(newsService.getById(id, userId));
    }


    // 新闻点赞
    @PostMapping(value = "/like")
    public Result<Void> like(@RequestParam("id") int id) {
        newsService.like(id);
        return Result.success();
    }
}
